import request from '@/utils/request';
import type { ResponseBaseData } from '@/api/model/baseModel';

export function getBpmPiModelByDefineId({ id, type }): Promise<ResponseBaseData<any>> {
  return request.get(`/bpm/design/getProcessJson/v1?id=${id}&type=${type}`);
}

/**
 * 根据过程定义key查询流程节点信息
 * @param processKey
 * @returns
 */
export function getBpmPiActivityListByProcessKey(processKey): Promise<ResponseBaseData<any>> {
  return request.get(`/bpm/bpmpi/bpmpiprocesss/getProcessActivityList/v1?processKey=${processKey}`);
}

/**
 * 根据过程实例id查询过程节点实例信息
 * @param procInstId
 * @returns
 */
export function getActivityInstanceListByProcInstId(procInstId): Promise<ResponseBaseData<any>> {
  return request.get(`/bpm/bpmpi/bpmpiprocesss/getActivityInstanceListByProcInstId/v1?procInstId=${procInstId}`);
}

/**
 * 获取过程实例图数据
 * @param bpmPiInstanceId 过程实例id
 * @returns
 */
export function getBpmPiModelByInstanceId(bpmPiInstanceId: string): Promise<ResponseBaseData<any>> {
  return request.get(`/bpm/bpmmodel/appBpmPicRest/getProcessPicInfo/v1?processInstanceId=${bpmPiInstanceId}`);
}
/**
 * 获取过程实例节点配置信息(人员、部门、计划完成时间等)
 * @param bpmPiInstanceId 过程实例id
 * @returns
 */
export function getBpmPiInstanceCandidatesByInstanceId(bpmPiInstanceId) {
  return request.get(`/bpm/bpmpi/bpmpiinstancecandidates/find-list-by-instanceid/${bpmPiInstanceId}/v1`);
}

/**
 * 获取过程实例执行历史
 * @param instanceId 实例id
 * @returns
 */
export function getBpmPiHistoryActivityList(instanceId: string) {
  return request.get(`/bpm/bpm/clientbpmdisplayaction/getHistoryActivityList/v1/${instanceId}`);
}

/**
 * 根据流程实例Id获取所属过程实例的下一步节点(集合)
 * @param bpmInstanceId 流程实例id
 * @returns
 *
 */
export function getParentPINextActivitys(bpmInstanceId: string) {
  return request.get(`/bpm/bpmpi/bpmpiinstancecandidates/getParentPINextActivitys/v1?processInstanceId=${bpmInstanceId}`);
}

/**
 * 根据流程实例Id获取所属过程实例Id
 * @param bpmInstanceId 流程实例id
 * @returns {parentEntryId} 过程实例Id
 */
export function getParentPIInstanceId(bpmInstanceId): Promise<ResponseBaseData<{ parentEntryId: string; activityName: string }>> {
  return request.post(`/bpm/bpmengine/reform/getProcessLevel/v1`, { dto1: bpmInstanceId });
}

/**
 * 保存过程实例的人员配置数据
 * @param params 过程实例配置数据
 * @returns
 */
export function saveNodeCandidate(params): Promise<ResponseBaseData<any>> {
  return request.post(`/bpm/bpmpi/bpmpiinstancecandidates/save-node-candidate/v1`, params);
}
